﻿package map 
{
	import Common.GameDefine;
	import flash.display.Bitmap;
	
	/**
	 * ...
	 * @author fox
	 */
	public class MapScene 
	{
		public var id:int = 0;
		
		public var maxX:int = 0;
		public var maxY:int = 0;
		
		public var gridSize:int = 0;
		
		public var data:String = "";
		
		public var npc:Array;
		
		public var bitmap:Bitmap = null;
		
		public function MapScene() 
		{
		}
		
		public function init():void
		{
			npc = new Array();
			
		}
		
		public function release():void
		{
			for ( var i:int = 0; i < npc.length ; ) 
			{
				npc[i].grid = null;
				npc.pop();
			}
			
			npc = null;
		}
		
		public function addMonster( id:int , x:int , y:int ):void
		{
			
		}
		
		public function addNPC( id:int , x:int , y:int ):void
		{
			var o:Object = new Object();
			o.id = id;
			o.grid = new MapGrid( x , y );
			
			npc.push( o );
		}
		
		public function isBlock( x:int , y:int ):Boolean
		{
			var n:int = int( data.substr( y * maxX + x , 1 ) );
			
			if ( n == GameDefine.BLOCK || n == GameDefine.BLOCK + GameDefine.SHADOW ) 
			{
				return true;
			}
			
			return false;
		}
		
		public function isShadow( x:int , y:int ):Boolean
		{
			var n:int = int( data.substr( y * maxX + x , 1 ) );
			
			if ( n == GameDefine.SHADOW || n == GameDefine.BLOCK + GameDefine.SHADOW ) 
			{
				return true;
			}
			
			return false;
		}
		
	}
	
}